package com.feihong.txgw.dialog;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.feihong.txgw.R;
import com.feihong.txgw.http.HttpTools;
import com.feihong.txgw.model.bean.user.User;
import com.feihong.txgw.utils.UserLoginInfo;
import com.feihong.txgw.utils.glidehttps.GlideOptionsSetting;
import com.feihong.txgw.utils.sign.SignToken;

import java.util.HashMap;

import cn.pedant.SweetAlert.SweetAlertDialog;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * @name txgw_app
 * @class name：com.feihong.txgw.dialog
 * @class describe: 用户个人二维码展示
 * @author wangziheng
 * @time 2017/7/31 15:34
 * @change
 * @chang time
 * @class describe
 */
public class ZCodeDialog {

    private CircleImageView mPersonIcon;
    private TextView mPersonTel;
    private ImageView mPersonZCodeImg;
    private Context mContext;
    private SweetAlertDialog mDialog;
    View view;
    public ZCodeDialog(Context context) {
        mContext = context;
        initView();
    }

    private void initView() {

        LayoutInflater inflater = LayoutInflater.from(mContext);
        view = inflater.inflate(R.layout.dialog_z_code_show_layout,null);

        mPersonZCodeImg = (ImageView) view.findViewById(R.id.z_code_person_code);
        mPersonIcon = (CircleImageView) view.findViewById(R.id.z_code_person_icon);
        mPersonTel = (TextView) view.findViewById(R.id.z_code_person_tel);
        String strPic = null;
        User user = UserLoginInfo.getUserInfo();
        if(user != null){
            strPic = user.getUserPic();
        }

        String url = HttpTools.USER_QRCODE_IMAGE_URL + new SignToken().setSigen(new HashMap());
        Glide.with(mContext).load(url).apply(new RequestOptions().error(R.mipmap.user_head)).into(mPersonZCodeImg);
        Glide.with(mContext).load(TextUtils.isEmpty(strPic) ? null : strPic).apply(GlideOptionsSetting.getDefaultOptions(R.mipmap.user_head,R.mipmap.user_head)).into(mPersonIcon);
        mPersonTel.setText(UserLoginInfo.getUserInfo().getUserName());

        mDialog = new SweetAlertDialog(mContext, SweetAlertDialog.NORMAL_TYPE);
        mDialog.setCustomView(view);
        mDialog.setCancelable(true);
        mDialog.setTitle("");
        mDialog.setContentText("");
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.showCancelButton(false);
        mDialog.showContentText(false);
    }

    public void show() {
        if(mDialog!=null&&mDialog.isShowing())
        {
            mDialog.dismiss();
        }
        mDialog.show();
        if(mDialog.getButton(SweetAlertDialog.BUTTON_CONFIRM)!=null) {
            mDialog.getButton(SweetAlertDialog.BUTTON_CONFIRM).setVisibility(View.GONE);
        }

        if(mDialog.getButton(SweetAlertDialog.BUTTON_CANCEL)!=null) {
            mDialog.getButton(SweetAlertDialog.BUTTON_CANCEL).setVisibility(View.GONE);
        }
    }
}
